<template>
    <div>
      <div class="navbar">
        <input type="checkbox" id="checkbox">
        <label for="checkbox">
          <i class="fa fa-bars" aria-hidden="true"></i>
        </label>
        <ul class="lli">
          <li>
            <img :src="userMap.userImg">
            <span>欢迎您，{{ userMap.userName }}！</span>
          </li>
          <li>
            <button >欢迎您</button>
          </li>
          <li>
            <!-- <button @click="goUserInfo()">个人中心</button> -->
            <button >{{ userMap.userName }}</button>
          </li>
          <li>
            <!-- <button @click="goUserNews()">论坛中心</button> -->
            <button >请点餐</button>
          </li>
        </ul>
        <div class="main">
          <!-- 商家列表渲染 -->
            <div class="merlist" >
              <div class="mer" v-for="m in merList" :key="m.merId" @click="go(m.merId)">
                <div class="merImg"><img class="img" :src="m.merImg"></div>
                <div class="merName">{{ m.merName }}</div>
              </div>
            </div>
        </div>
      </div>
    </div>
  </template>
  
  <script>
  import UserApi from "@/api/apiPb/User_order"
  export default {
      data() {
        return {
          merList: [],
          userMap:{},
          // userId:this.$router.query.userId //用户id，来自登陆界面
          userId:2
        }
      },
      created() {
        this.userId=this.$route.query.userId; //连接login数据库之后解开
        //获取商家列表
        this.fetchData();
        //获取用户信息
        this.getUserData();
      },
      methods: {
        go(merId){
          this.$router.push({path:'/UserOrderPage/MerchatPage',query: {merId:merId,userId:this.userId}})
        },
        goUserInfo(){
          this.$router.push({path:'/UserInfo',query: {userId:this.userId}})
        },
        goUserNews(){
          this.$router.push({path:'/ForumPage',query: {userId:this.userId}})
        },
        fetchData() {
          //编写一个方法请求后端的接口，把返回的数据赋值list
          UserApi.getMerchatList().then(response => {
            //  //把返回的结果赋值模型
            this.merList = response.data.data
          })
        },
        getUserData(){
          UserApi.getUserInfo(this.userId).then(response=>{
            this.userMap = response.data.data
          })
        }
      },
}
  </script>
  <style scoped>
  * {
    /* 初始化 取消内外边距 */
    margin: 0;
    padding: 0;
  }
  button{
    width: 100%;
    height: 100%;
    font-size: large;
    font-weight: bold;
    color: white;
    background-color: lightskyblue;
    border-radius: 45%;
  }
  button:hover{
    box-shadow: 10px 10px yellow;
  }

  
  
  body {
    /* 溢出隐藏 */
    margin: 0;
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
  }
  .merlist{
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
  }
  .mer{
    position: relative;
    width: 100%;
    height: 200px;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    border:1px solid black;
    background: rgb(156, 243, 243);
  }
  .merImg{
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .merName{
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: left;
  }
  .img{
    position: relative;
    width: 100px;
    height: 100px;
    
  }
  
  .navbar{
        /* 相对定位 */
        position: relative;
        /* 100%窗口宽度 */
        width: 100vw;
        height: 100%;
        display: flex;
    }
    .lli{
      position: fixed;
      top: 0px;
      left: 220px;
      z-index: 999;
    }
    .main{
        flex: 1;
        height: calc(100vh - 43px);
        width: auto;
        position: relative;
        top: 43px;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    #checkbox{
        /* 隐藏复选框 */
        display: none;
    }
    .navbar label{
        position: absolute;
        top: 0;
        left: 70px;
        width: 100%;
        height: 43px;
        font-size: 30px;
        color: #5a738e;
        background-color: #ededed;
        padding-left: 20px;
        border: 1px solid #d9dee4;
        cursor: pointer;
        /* 加个动画过渡 */
        transition: all 0.5s;
    }
    .navbar ul{
        list-style: none;
        width: 70px;
        /* 100%窗口高度 */
        height: 100vh;
        background-color: #2a3f54;
        transition: all 0.5s;
        /* 再加个溢出隐藏 */
        overflow: hidden;
    }
    .navbar ul li{
        height: 70px;
        margin-bottom: 10px;
    }
    .navbar ul li:first-child{
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 0 10px;
    }
    .navbar ul li:first-child img{
        width: 50px;
        height: 50px;
        border-radius: 50%;
    }
    .navbar ul li:first-child span{
        color: #fff;
        /* 文字禁止换行 */
        white-space: nowrap;
        padding-left: 10px;
        /* 先把文字隐藏 */
        display: none;
    }
    .navbar ul li a{
        display: flex;
        justify-content: center;
        align-items: center;
        /* 垂直排列 */
        flex-direction: column;
        width: 100%;
        height: 100%;
        color: #d1d1d1;
        /* 去掉下划线 */
        text-decoration: none;
    }
    .navbar ul li a i{
        font-size: 25px;
        margin-bottom: 10px;
    }
    .navbar ul li a span{
        font-size: 12px;
        white-space: nowrap;
    }
    .navbar ul li a:hover{
        color: #fff;
        background-color: #35495d;
    }
    /* :checked选择器是判断复选框是否被选中 */
    /* +是相邻兄弟选择器，找到input的下一个兄弟label */
    .navbar input:checked + label{
        left: 200px;
    }
    /* ~也是兄弟选择器，但它可以找到隔了几代的兄弟 */
    .navbar input:checked ~ ul{
        width: 200px;
    }
    .navbar input:checked ~ ul li:first-child{
        /* 将居中改为开头对齐 */
        justify-content: flex-start;
    }
    .navbar input:checked ~ ul li:first-child span{
        /* 文字显示 */
        display: block;
    }
    .navbar input:checked ~ ul li a{
        flex-direction: row;
        justify-content: flex-start;
    }
    .navbar input:checked ~ ul li a i{
        font-size: 18px;
        margin: 0 15px 0 30px;
    }
    .navbar input:checked ~ ul li a span{
        font-size: 14px;
    }</style>